/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.sample.library.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import com.sample.library.model.Author;
import com.sample.library.model.AuthorModel;
import com.sample.library.model.AuthorSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Author service. Represents a row in the &quot;Author&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.sample.library.model.AuthorModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link AuthorImpl}.
 * </p>
 *
 * @author Nguyen Tuan Anh
 * @see AuthorImpl
 * @see com.sample.library.model.Author
 * @see com.sample.library.model.AuthorModel
 * @generated
 */
@JSON(strict = true)
public class AuthorModelImpl extends BaseModelImpl<Author>
	implements AuthorModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a author model instance should use the {@link com.sample.library.model.Author} interface instead.
	 */
	public static final String TABLE_NAME = "Author";
	public static final Object[][] TABLE_COLUMNS = {
			{ "authorId", Types.BIGINT },
			{ "firstMiddleName", Types.VARCHAR },
			{ "lastName", Types.VARCHAR },
			{ "fullName", Types.VARCHAR },
			{ "birthDay", Types.TIMESTAMP },
			{ "email", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table Author (authorId LONG not null primary key IDENTITY,firstMiddleName VARCHAR(75) null,lastName VARCHAR(75) null,fullName VARCHAR(75) null,birthDay DATE null,email VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table Author";
	public static final String DATA_SOURCE = "sampleDataSource";
	public static final String SESSION_FACTORY = "sampleSessionFactory";
	public static final String TX_MANAGER = "sampleTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.sample.library.model.Author"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.sample.library.model.Author"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = false;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Author toModel(AuthorSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Author model = new AuthorImpl();

		model.setAuthorId(soapModel.getAuthorId());
		model.setFirstMiddleName(soapModel.getFirstMiddleName());
		model.setLastName(soapModel.getLastName());
		model.setFullName(soapModel.getFullName());
		model.setBirthDay(soapModel.getBirthDay());
		model.setEmail(soapModel.getEmail());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Author> toModels(AuthorSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Author> models = new ArrayList<Author>(soapModels.length);

		for (AuthorSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final String MAPPING_TABLE_AUTHORBOOK_NAME = "AuthorBook";
	public static final Object[][] MAPPING_TABLE_AUTHORBOOK_COLUMNS = {
			{ "authorId", Types.BIGINT },
			{ "bookId", Types.BIGINT }
		};
	public static final String MAPPING_TABLE_AUTHORBOOK_SQL_CREATE = "create table AuthorBook (authorId LONG not null,bookId LONG not null,primary key (authorId, bookId))";
	public static final boolean FINDER_CACHE_ENABLED_AUTHORBOOK = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.AuthorBook"), true);
	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.sample.library.model.Author"));

	public AuthorModelImpl() {
	}

	public long getPrimaryKey() {
		return _authorId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAuthorId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_authorId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	public Class<?> getModelClass() {
		return Author.class;
	}

	public String getModelClassName() {
		return Author.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("authorId", getAuthorId());
		attributes.put("firstMiddleName", getFirstMiddleName());
		attributes.put("lastName", getLastName());
		attributes.put("fullName", getFullName());
		attributes.put("birthDay", getBirthDay());
		attributes.put("email", getEmail());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long authorId = (Long)attributes.get("authorId");

		if (authorId != null) {
			setAuthorId(authorId);
		}

		String firstMiddleName = (String)attributes.get("firstMiddleName");

		if (firstMiddleName != null) {
			setFirstMiddleName(firstMiddleName);
		}

		String lastName = (String)attributes.get("lastName");

		if (lastName != null) {
			setLastName(lastName);
		}

		String fullName = (String)attributes.get("fullName");

		if (fullName != null) {
			setFullName(fullName);
		}

		Date birthDay = (Date)attributes.get("birthDay");

		if (birthDay != null) {
			setBirthDay(birthDay);
		}

		String email = (String)attributes.get("email");

		if (email != null) {
			setEmail(email);
		}
	}

	@JSON
	public long getAuthorId() {
		return _authorId;
	}

	public void setAuthorId(long authorId) {
		_authorId = authorId;
	}

	@JSON
	public String getFirstMiddleName() {
		if (_firstMiddleName == null) {
			return StringPool.BLANK;
		}
		else {
			return _firstMiddleName;
		}
	}

	public void setFirstMiddleName(String firstMiddleName) {
		_firstMiddleName = firstMiddleName;
	}

	@JSON
	public String getLastName() {
		if (_lastName == null) {
			return StringPool.BLANK;
		}
		else {
			return _lastName;
		}
	}

	public void setLastName(String lastName) {
		_lastName = lastName;
	}

	@JSON
	public String getFullName() {
		if (_fullName == null) {
			return StringPool.BLANK;
		}
		else {
			return _fullName;
		}
	}

	public void setFullName(String fullName) {
		_fullName = fullName;
	}

	@JSON
	public Date getBirthDay() {
		return _birthDay;
	}

	public void setBirthDay(Date birthDay) {
		_birthDay = birthDay;
	}

	@JSON
	public String getEmail() {
		if (_email == null) {
			return StringPool.BLANK;
		}
		else {
			return _email;
		}
	}

	public void setEmail(String email) {
		_email = email;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
			Author.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Author toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (Author)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		AuthorImpl authorImpl = new AuthorImpl();

		authorImpl.setAuthorId(getAuthorId());
		authorImpl.setFirstMiddleName(getFirstMiddleName());
		authorImpl.setLastName(getLastName());
		authorImpl.setFullName(getFullName());
		authorImpl.setBirthDay(getBirthDay());
		authorImpl.setEmail(getEmail());

		authorImpl.resetOriginalValues();

		return authorImpl;
	}

	public int compareTo(Author author) {
		long primaryKey = author.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		Author author = null;

		try {
			author = (Author)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = author.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
	}

	@Override
	public CacheModel<Author> toCacheModel() {
		AuthorCacheModel authorCacheModel = new AuthorCacheModel();

		authorCacheModel.authorId = getAuthorId();

		authorCacheModel.firstMiddleName = getFirstMiddleName();

		String firstMiddleName = authorCacheModel.firstMiddleName;

		if ((firstMiddleName != null) && (firstMiddleName.length() == 0)) {
			authorCacheModel.firstMiddleName = null;
		}

		authorCacheModel.lastName = getLastName();

		String lastName = authorCacheModel.lastName;

		if ((lastName != null) && (lastName.length() == 0)) {
			authorCacheModel.lastName = null;
		}

		authorCacheModel.fullName = getFullName();

		String fullName = authorCacheModel.fullName;

		if ((fullName != null) && (fullName.length() == 0)) {
			authorCacheModel.fullName = null;
		}

		Date birthDay = getBirthDay();

		if (birthDay != null) {
			authorCacheModel.birthDay = birthDay.getTime();
		}
		else {
			authorCacheModel.birthDay = Long.MIN_VALUE;
		}

		authorCacheModel.email = getEmail();

		String email = authorCacheModel.email;

		if ((email != null) && (email.length() == 0)) {
			authorCacheModel.email = null;
		}

		return authorCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(13);

		sb.append("{authorId=");
		sb.append(getAuthorId());
		sb.append(", firstMiddleName=");
		sb.append(getFirstMiddleName());
		sb.append(", lastName=");
		sb.append(getLastName());
		sb.append(", fullName=");
		sb.append(getFullName());
		sb.append(", birthDay=");
		sb.append(getBirthDay());
		sb.append(", email=");
		sb.append(getEmail());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(22);

		sb.append("<model><model-name>");
		sb.append("com.sample.library.model.Author");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>authorId</column-name><column-value><![CDATA[");
		sb.append(getAuthorId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>firstMiddleName</column-name><column-value><![CDATA[");
		sb.append(getFirstMiddleName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastName</column-name><column-value><![CDATA[");
		sb.append(getLastName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>fullName</column-name><column-value><![CDATA[");
		sb.append(getFullName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>birthDay</column-name><column-value><![CDATA[");
		sb.append(getBirthDay());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>email</column-name><column-value><![CDATA[");
		sb.append(getEmail());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Author.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			Author.class
		};
	private long _authorId;
	private String _firstMiddleName;
	private String _lastName;
	private String _fullName;
	private Date _birthDay;
	private String _email;
	private Author _escapedModelProxy;
}